<?php
if(!isset($entite))
	exit();

require_once 'models/entite_historique.php';
require_once 'models/zone_geographique.php';
$admin = isset($_SESSION['isAdmin']);

include 'views/date_show.php';

if($admin)
echo '<br><form action="?section=entite_historique&action=update" method="post">';
echo '<input type="hidden" name="id" id="id" value="'. $entite->get_identite() .'">';
/**
 * Collones
 */
echo '<table border=1>';
echo '<tr>';
	echo '<th>ID</th>';
	echo '<th>Type</th>';
	echo '<th>Nom</th>';
	echo '<th>Description</th>';
	echo '<th>Wiki</th>';
	echo '<th>Profondeur</th>';
	echo '<th>Creation</th>';
	echo '<th>Dissolution</th>';
echo '</tr>';

/**
 * Lignes
 */

echo '<tr>';
	if($admin) {
		echo '<td>' . $entite->get_identite() . '</td>';
		echo '<td><select name="type" id="type">';
		foreach(entite_historique::$TYPES as $t)
		{
			echo '<option value="' . $t . '"';
			if($t == $entite->get_typeentite())
				echo ' selected ';
			echo '>' . $t . '</option>';
		}
		echo '</select>
		</td>';
		echo '<td><input type="text" name="nom" id="nom" value="' .$entite->get_nomentite() . '"/></td>';
		echo '<td><textarea name="description" id="description">' . $entite->get_descriptifentite() . '</textarea></td>';
		echo '<td><input type="url" name="wiki" id="wiki" value="' . $entite->get_wikientite() . '"/></td>';
		echo '<td><input type="number" name="profondeur" id="profondeur" value="' . $entite->get_profondeur() . '"/></td>';
		echo '<td><select name="creation" id="creation">';
		foreach($creations as $d)
		{
			echo '<option value="' . $d->get_iddate() . '"';
			if($d->get_reference() ==1)
				echo ' selected ';
			echo '>'. $d->get_date() .'</option>';
		}
		echo '</select>
		</td>';
		echo '<td><select name="dissolution" id="dissolution">';
		foreach($dissolutions as $d)
		{
			echo '<option value="' . $d->get_iddate() . '"';
			if($d->get_reference() ==1)
				echo ' selected ';
			echo '>'. $d->get_date() .'</option>';
		}
		echo '</select>
		</td>';
	}
	else {
		echo '<td>' . $entite->get_identite() . '</td>';
		echo '<td>' . $entite->get_typeentite() . '</td>';
		echo '<td>' . $entite->get_nomentite() . '</td>';
		echo '<td>' . $entite->get_descriptifentite() . '</td>';
		echo '<td><a href="' . $entite->get_wikientite() . '">'. $entite->get_wikientite(). '</a></td>';
		echo '<td>' . $entite->get_profondeur() . '</td>';
		echo '<td>' . $entite->get_creation()->get_date() . '</td>';
		echo '<td>' . $entite->get_dissolution()->get_date() . '</td>';
	}
echo '</tr>';

echo '</table>';
if($admin) {
	echo '<button type="submit">Valider les modifications</button>';
	echo '</form>';
}

if(isset($_GET['date']))
	include 'views/entite_historique_show_date.php';
else
	include 'views/entite_historique_show_general.php';

if($admin) {
	echo '<br>';
	echo '<form action="?section=entite_historique&action=delete" method="post">';
	echo '<input type="hidden" name="id" value="' . $entite->get_identite() . '">';
	echo '<button type="submit">Supprimer l\'entité</button>';
	echo '</from>';
}
?>